<%--
  Created by IntelliJ IDEA.
  User: 吴岳峰
  Date: 2017/07/17
  Time: 9:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@ include file="/common/meta.jsp"%>
    <title></title>
    <script>

        var selectKsId =null;
        var selectRoleId =null;

        $(function(){
            var height = findDimensions_height();
            $("#l_datagrid").height(height-50);
            $("#r_datagrid").height(height-50);
            loadKs();
            loadUserInfo();
        });
        function loadKs() {
            selectKsId =null;
            selectRoleId =null;
            var search = $("#search").val();
            $('#l_datagrid').datagrid(
                {
                    url:'/SysKeShi/findKsByCondition?condition='+encodeURI(search)+'&rmd='+ parseInt(Math.random()*100000),
                    method:'get',
                    rownumbers:true,
                    singleSelect:true,
                    autoRowHeight:false,
                    pagination:true,
                    clientPaging:true,
                    pageSize:15,
                    pageList:[10,15,20,25,30,40,50],
                    columns: [
                        [
                            {field: 'id', title: 'ID', hidden: true},
                            { field: 'code', title: '编号', width: '80px', align: 'left', halign: 'center' },
                            { field: 'name', title: '科室名称', width: "120px", align: 'left', halign: 'center' }

                        ]
                    ],
                    onSelect : function(index, row){
                        selectKsId=row.id;
                        var url = '/SysStaff/getKsStaff?ksId='+row.id;
                        loadUserInfo(url);
                    }
                }).datagrid('clientPaging');
        }
        function loadRole() {
            selectKsId =null;
            selectRoleId =null;
            var search = $("#search").val();
            $('#l_datagrid').datagrid(
                {
                    url:'/SysRole/findByCondition?condition='+encodeURI(search)+'&rmd='+ parseInt(Math.random()*100000),
                    method:'get',
                    rownumbers:true,
                    singleSelect:true,
                    autoRowHeight:false,
                    pagination:true,
                    clientPaging:true,
                    pageSize:15,
                    pageList:[10,15,20,25,30,40,50],
                    columns: [
                        [
                            {field: 'id', title: 'ID', hidden: true},
                            { field: 'xh', title: '序号', width: '80px', align: 'left', halign: 'center' },
                            { field: 'name', title: '角色名称', width: "120px", align: 'left', halign: 'center' }

                        ]
                    ],
                    onSelect : function(index, row){
                        selectRoleId=row.id;
                        var url = '/SysStaff/getRoleStaff?roleId='+row.id;
                        loadUserInfo(url);
                    }
                }).datagrid('clientPaging');
        }

        function loadUserInfo(url) {

            $('#r_datagrid').datagrid(
                {
                    url:url,
                    method:'get',
                    rownumbers:true,
                    singleSelect:true,
                    autoRowHeight:false,
                    columns: [
                        [
                            {field: 'id', title: 'ID', hidden: true},
                            { field: 'code', title: '序号', width: '80px', align: 'left', halign: 'center' },
                            { field: 'name', title: '角色名称', width: "120px", align: 'left', halign: 'center' },
                            { field: 'zc', title: '职称', width: '80px', align: 'left', halign: 'center' },
                            { field: 'zw', title: '职位', width: "120px", align: 'left', halign: 'center' },
                            {
                                field: 'operate', title: '操作', width: '100px', align: 'center', halign: 'center',
                                formatter: function (value, row, index) {
                                    var str = '<input type=\'checkbox\'name="uname" align="center" ' +
                                        'class=\'btn btn-info bi-glyphicon\' value="' + row.id + '"></button>';
                                    return str;
                                }
                            }

                        ]
                    ]
                    ,
                    onLoadSuccess : function(index, row){
                        $("input:checkbox[name='uname']").prop("checked",true);
                    }
                });
        }

        function saveInfo() {
//            var rows = $("#r_datagrid").datagrid("getRows");
            var ids = [];
            $("input:checkbox[name='uname']:checked").each(function(i){
                var t ={
                    name : "id"+i,
                    value :$(this).val()
                };
                ids.push(t)
            })

            $.ajax({
                type: 'post',
                url: '/SysUserInfo/saveHome?homePageId=${homePageId}',
                dataType: 'JSON',
                contentType: "application/json",
                data: JSON.stringify(ids),
                success: function(data) {
                    if (data.success == true) {
                        layerMsg(data.msg);
                    } else {
                        layerError(data.msg);
                    }
                }
            });
        }

    </script>

</head>
<body>




<div class="navheader form-inline" style="padding:0 5px;height:40px;">
    <div class=" form-group">
        <div>
            <label for="search">检索内容：</label>
            <input type="text" class="form-control" name="search" id="search" style="width:120px;" placeholder="患者姓名、病人编号"/>
            <button type="button" class="btn btn-success " onclick="loadKs()">
                <span class="glyphicon glyphicon glyphicon-search"></span>科室人员
            </button>

            <button type="button" class="btn btn-success " onclick="loadRole()">
                <span class="glyphicon glyphicon glyphicon-search"></span> 角色人员
            </button>

        </div>
    </div>

    <div class="btn-group-right">
        <div class="btn-group "  role="group">
            <button type="button" class="btn btn-default bi-btn-width90" onclick="saveInfo()">确定</button>
        </div>
    </div>

</div>

<div style="margin:0 5px; overflow: hidden;" >
    <!--左边表格-->
    <div style="width:30%;float:left;display:inline-block;padding-right:5px;border-right:1px dotted #ccc;" >
        <table id="l_datagrid" class="datagrid"></table>

    </div>
    <!--右边表格 -->
    <div style="width:70%;float:right;display:inline-block;padding-left:5px;">
        <table id="r_datagrid" class="datagrid">
            <!--右边表格未定义-->
        </table>
    </div>
</div>



</body>
</html>
